import Mock from 'mockjs'

//  username:'孙蒙恩',
//       area:"四平区",
//       zc:"精神病人",
//       keshi:"神经科",
//       date: '肾病',
//       address:"上海市普陀区金沙江路 1518 弄",
//       czuo: '删除'
var Arr = []
for (var i = 0; i < 100; i++) {
    let num = Mock.mock('@natural(0, 2)')
    Arr.push({
        id: new Date().getTime(),
        username: Mock.mock('@cname()'),
        area: ['东院区', '西院区', '北院区'][num],
        zc: ['主治医师', '主任医师', '副主任医师'][num],
        keshi: ['内科-肾内科', '外科-神经科', '外科-神经科'][num],
        address: ['钻研学习医学科学技术，挽救生命以治病为业的人，', '主持医患沟通，学术讨论，新技术推广、预后分析、公众教育、护理示教、康复培训', '获得了科室同事和患者的高度评价,同时也取得了较好的社会效益和经济效益 在教学方面能高质量完成院里安排的教学任务'][num],
    })
}
import { param2Obj } from '../utils/myUtils'
//造数据
export default {

    HomeData: config => {


        const { search, page, pagesize } = param2Obj(config.url)

        var res = []
        if (search) {
            res = Arr.filter(item => {
                //  console.log(item);
                return item.username.indexOf(search) != -1
            })
        } else {
            res = Arr
        }

        var newRes = res.filter((item, index) => {
            return (page - 1) * pagesize <= index && index < page * pagesize
        })

        return {
            code: 200,
            msg: "请求/查询/搜索成功",
            data: newRes,
            total: res.length
        }
    },
    delData: config => {

        const { id } = JSON.parse(config.body)
            //删除逻辑
        Arr.forEach((item, index) => {
            if (item.id == id) {
                console.log(item);
                Arr.splice(index, 1)
            }
        })
        return {
            code: 200,
            msg: "删除成功",
            data: null
        }
    },
    //修改
    updateData: config => {
        // const{zc} = JSON.parse(config.body)
        // Arr.forEach(item=>{
        //   if(item.id == id){
        //     item.zc = zc
        //   }
        // })
        return {
            code: 200,
            msg: "修改成功",
            data: null
        }
    },


    //搜索
    //全部删除
    AlldelData: config => {
        const { ids } = JSON.parse(config.body)
        var res = Arr.filter(item => {
            return ids.indexOf(item.id) == -1
        })
        Arr = res
        return {
            code: 200,
            msg: "全部删除成功",
            data: null
        }
    },
    saveData: config => {
        const { name, school, ks, zc, bq, gh, zcf, desc, delivery } = JSON.parse(config.body)
            // console.log(name,school,ks,zc,bq,gh,zcf,desc,delivery);
        Arr.unshift({

            id: new Date().getTime(),
            username: name,
            area: school,
            zc: zc,
            keshi: ks,
            address: desc,
        })
        return {
            code: 200,
            msg: "添加成功",
            data: null
        }
    }
}